package com.neudu.glsb.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.enums.SqlKeyword;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.neudu.glsb.dto.IngredientsPageDTO;
import com.neudu.glsb.pojo.Ingredients;
import com.neudu.glsb.service.IngredientsService;
import com.neudu.glsb.mapper.IngredientsMapper;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
* @author Lenovo
* @description 针对表【ingredients(原料信息)】的数据库操作Service实现
* @createDate 2025-04-16 22:28:32
*/
@Service
public class IngredientsServiceImpl extends ServiceImpl<IngredientsMapper, Ingredients>
    implements IngredientsService{
@Override
    public IPage<Ingredients> pageByCondition(IngredientsPageDTO dto) {
        Page<Ingredients> page = Page.of(dto.getPageNum(), dto.getPageSize());
        LambdaQueryWrapper<Ingredients> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(StringUtils.hasText(dto.getIngredientName()),
                Ingredients::getIngredientName, dto.getIngredientName());
        wrapper.eq(StringUtils.hasText(dto.getIngredientType()),
                Ingredients::getIngredientType, dto.getIngredientType());
        // 库存状态
        if ("normal".equals(dto.getStockStatus())) {
            wrapper.apply("stock >= threshold");
        } else if ("warning".equals(dto.getStockStatus())) {
            wrapper.apply("stock >= threshold");
        }
        return page(page, wrapper);
    }
    // 在 IngredientsServiceImpl 里实现



}




